package Leo.social;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.social.security.SocialAuthenticationFilter;
import org.springframework.social.security.SpringSocialConfigurer;

public class SpringSocialConfigurerImpl extends SpringSocialConfigurer {

    private String socialUrl;

    public SpringSocialConfigurerImpl(){

    }

    public SpringSocialConfigurerImpl(String socialUrl){
        this.socialUrl = socialUrl;
    }
    /**
     * Performs post processing of an object. The default is to delegate to the
     * {@link ObjectPostProcessor}.
     *
     * @param object the Object to post process
     * @return the possibly modified Object to use
     */
    @Override
    protected <T> T postProcess(T object) {
        SocialAuthenticationFilter filter = (SocialAuthenticationFilter) super.postProcess(object);
        if(StringUtils.isNotBlank(socialUrl)) {
            filter.setFilterProcessesUrl(socialUrl);
        }
        return (T)filter;
    }

    public String getSocialUrl() {
        return socialUrl;
    }

    public void setSocialUrl(String socialUrl) {
        this.socialUrl = socialUrl;
    }
}
